package com.agile.springboot.service.impl;

import com.agile.springboot.service.LoginService;
import com.agile.springboot.dao.UserMapper;
import com.agile.springboot.entity.User;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

@Service
public class LoginServiceImpl extends ServiceImpl<UserMapper,User> implements LoginService {

    @Resource
    UserMapper userMapper;

    /**
     * 账号密码登录
     * @param user 用户实体
     * @return List<User>用户列表
     */
    @Override
    public List<User> loginUser(User user) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(User::getUsername, user.getUsername()).eq(User::getPassword, user.getPassword());
        List<User> userList = userMapper.selectList(queryWrapper);
        return userList;
    }

    /**
     * 检测当前手机号是否已经注册过
     * @param user 用户实体
     * 所必须的参数为 phone 用户手机号属性
     * @return List<User>用户列表
     */
    @Override
    public List<User> phoneUser(User user) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(User::getPhone, user.getPhone());
        List<User> userList = userMapper.selectList(queryWrapper);
        return userList;
    }

    /**
     * 检测当前用户名是否已经注册过
     * @param user 用户实体
     * 所必须的参数为 username 用户名属性
     * @return List<User>用户列表
     */
    @Override
    public List<User> searchUserByUsername(User user) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(User::getUsername, user.getUsername());
        List<User> userList = userMapper.selectList(queryWrapper);
        return userList;
    }
}
